<?php
namespace app\test\controller;

use think\Db;
use think\Controller;
use think\facade\Build;
use think\facade\Env;
class Test extends Controller
{

    public function create_controller($data){
            $this->assign($data);
          // 改变当前操作的模板路径
          $path=Env::get('module_path').'view\template\controller\controller.html';
          return $this->fetch($path);
      }
    public function save_controller_file(){
        $data['app_namespace']='app';
        $data['module_name']='shop_admin';
        $data['table_title']='店铺管理员';
        $data['module_no']='1';
        $data['controller_no']='1';
        $data['group_name']='店铺后台管理员';
        $data['table_name']="shop_admin";
        $data['author']='梁敏';
        $table_comment=get_table_comment(parse_name($data['table_name'],true));

        $data['table_comment']=$table_comment;
        $module_files= array(
            '__file__'   => ['common.php'],
            '__dir__'    => ['behavior', 'controller','validate', 'model', 'view'],
            'controller' => ['Index'],
            'model'      => [],
            'view'       => ['index/index']
        );
        \think\facade\Build::module($data['module_name'],$module_files);

        $controller_file=Env::get('app_path').parse_name($data['module_name']).'/controller/'.parse_name($data['table_name'],true).'.php';
        $conten="<?php".$this->create_controller($data);
        file_put_contents($controller_file,$conten);


        $model_file=Env::get('app_path').parse_name($data['module_name']).'/model/'.parse_name($data['table_name'],true).'.php';
        $conten="<?php".$this->create_model($data);
        file_put_contents($model_file,$conten);

        $validate_file=Env::get('app_path').parse_name($data['module_name']).'/validate/'.parse_name($data['table_name'],true).'.php';
        $conten="<?php".$this->create_validate($data);
        file_put_contents($validate_file,$conten);
    }
    public function create_model($data){
        $this->assign($data);
        // 改变当前操作的模板路径
        $path=Env::get('module_path').'view\template\model\model.html';
        return $this->fetch($path);
    }

    public function create_validate($data){
        $this->assign($data);
        // 改变当前操作的模板路径
        $path=Env::get('module_path').'view\template\validate\validate.html';
        return $this->fetch($path);
    }


}